package com.adams.core.exception;



/**
 * 
 * File Name : BusinessException.java
 * 
 * @Description : 业务层异常封闭类,支持到error_massage.xml配置文件中取配置信息
 * @author 904203 肖震
 */
public class BusinessException extends Exception
{


	private static final long serialVersionUID = 1L;
	
	/**
	 * 默认错误代码
	 */
	public static final String DEFAULT_ERROR_CODE = "default_error";

	/**
	 * 
	 * Description : <Detail Description for method>
	 * 
	 * @return
	 * 
	 */
	public String getErrorText()
	{
		if (errorCode == null || errorCode.trim().length() == 0)
		{
			return null;
		}
		return ExceptionConfigCache.getInstance().getErrorText(errorCode);
	}

	/**
	 * 错误返回码
	 */
	private String errorCode;

	public BusinessException(String errorCode, String message, Throwable cause)
	{
		super(message, cause);
		this.errorCode = errorCode;
	}

	public BusinessException(String message, Throwable cause)
	{
		super(message, cause);
	}

	public BusinessException(Throwable cause)
	{
		super(cause);
		if (cause instanceof BusinessException)
		{
			BusinessException e = (BusinessException) cause;
			this.errorCode = e.errorCode;
		}
	}

	public BusinessException(String errorCode)
	{
		super();
		this.errorCode = errorCode;
	}

	public BusinessException(String errorCode, String message)
	{
		super(message);
		this.errorCode = errorCode;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode()
	{
		return errorCode;
	}

	/**
	 * @param errorCode
	 *            the errorCode to set
	 */
	public void setErrorCode(String errorCode)
	{
		this.errorCode = errorCode;
	}

}
